/*
 * @Author: your name
 * @Date: 2021-03-20 11:40:40
 * @LastEditTime: 2021-03-23 20:34:06
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \danshang-admin\mock\productData\index.js
 */
//模拟商品管理数据
const Mock = require("mockjs");

const List = [];
const count = 100;

const baseContent =
  '<p>I am testing data, I am testing data.</p><p><img src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>';

for (let i = 0; i < count; i++) {
  List.push(
    Mock.mock({
      id: `${i}`,
      address: "@ctitle",
      name: "@cname",
      attribute: "@ctitle",
      zip: "@id",
      city: "@county(true)",
      province: "@county(true)",
      date: "@now",
      timestamp: +Mock.Random.date("T"),
      author: "@first",
      reviewer: "@first",
      title: "@ctitle(15, 20)",
      content_short: "mock data",
      content: baseContent,
      forecast: "@float(0, 100, 2, 2)",
      importance: "@integer(1, 3)",
      "type|1": ["CN", "US", "JP"],
      "status|1": ["published", "draft"],
      display_time: "@datetime",
      comment_disabled: true,
      pageviews: "@integer(300, 5000)",
      "image_uri|1": [
        "https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3",
        "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2202780618,895893289&fm=26&gp=0.jpg",
        "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=360400461,2955275651&fm=26&gp=0.jpg",
        "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1709216491,2536617744&fm=26&gp=0.jpg",
        "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3036316726,676055399&fm=26&gp=0.jpg",
        "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3623279689,206753714&fm=26&gp=0.jpg"
      ],
      platforms: ["a-platform"],
      "price|1-100": 100,
      "volume|100-1000": 1000,
      "repertory|1000-10000": 10000,
      "rank|1-100": 100,
      status: true
    })
  );
}
module.exports = [
  {
    url: "/vue-element-admin/product",
    type: "get",
    response: config => {
      const {
        importance,
        type,
        title,
        page = 1,
        limit = 20,
        sort
      } = config.query;

      let mockList = List.filter(item => {
        if (importance && item.importance !== +importance) return false;
        if (type && item.type !== type) return false;
        if (title && item.title.indexOf(title) < 0) return false;
        return true;
      });

      if (sort === "-id") {
        mockList = mockList.reverse();
      }

      const pageList = mockList.filter(
        (item, index) => index < limit * page && index >= limit * (page - 1)
      );

      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      };
    }
  }
];
